package com.etasist;

/**
 * @author issa rabba
 *
 */

//import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Runtime;

public class RunCommand {

	public static void main(String[] args){
		//runRemoreCommand("java -version");

	}
	/**
	 * 
	 * @parm @param command
	 * @parm @return
	 */
    public static String runRemoreCommand(String command) {

        String s = null;
		StringBuffer commandResult= new StringBuffer();
        try {    	
            Process p = Runtime.getRuntime().exec(command);
            
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            // read the output from the command
            while ((s = stdInput.readLine()) != null) {
				commandResult.append(s);
				commandResult.append(System.getProperty("line.separator"));
            }
            
            // read any errors from the attempted command
            while ((s = stdError.readLine()) != null) {
				commandResult.append(s);
				commandResult.append(System.getProperty("line.separator"));
            }
			commandResult.append("<EOF>");
			return commandResult.toString();
        }
        catch (Exception e) {
			commandResult.append("Error");
			commandResult.append("<EOF>");
        }
		commandResult.append("<EOF>");
        return commandResult.toString();
    }
    
}